//
//  MKHud.m
//  Teleport
//
//  Created by RLY on 2020/5/15.
//  Copyright © 2020 xxt. All rights reserved.
//

#import "TJHud.h"
#import "SPActivityIndicatorView.h"

#define hudOpacity 0.8f
#define Font [UIFont systemFontOfSize:15]

@implementation TJHud


+ (void)showTopAutoHideMessage:(nullable NSString *)message{
    if (NSThread.currentThread.isMainThread) {
        [self showAutoHideMessage:message inView:[UIApplication sharedApplication].delegate.window andIsTop:YES];
    } else {
        dispatch_async(dispatch_get_main_queue(), ^{
         [self showAutoHideMessage:message inView:[UIApplication sharedApplication].delegate.window andIsTop:YES];
        });
    }
}

+ (void)showAutoHideMessage:(nullable NSString *)message {
    if (NSThread.currentThread.isMainThread) {
        [self showAutoHideMessage:message inView:[UIApplication sharedApplication].delegate.window andIsTop:NO];
    } else {
        dispatch_async(dispatch_get_main_queue(), ^{
         [self showAutoHideMessage:message inView:[UIApplication sharedApplication].delegate.window andIsTop:NO];
        });
    }
}

+ (TJHud *)showAutoHideMessage:(nullable NSString *)message inView:(UIView *)view andIsTop:(BOOL) istop{
    if (!message.length) return nil;
    TJHud *hud = [TJHud showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.7];
    hud.label.textColor = UIColor.whiteColor;
    hud.label.text = message;
    hud.label.font = MediumFont(15);
    hud.margin = 10;
    hud.removeFromSuperViewOnHide = YES;
    CGPoint offset = hud.offset;
    if (istop) {
         offset.y = 10;
    }else{
          offset.y = KScreenHeight * 0.5 - 200;
    }
  
    hud.offset = offset;
    [hud hideAnimated:YES afterDelay:2];
    return hud;
}



+ (void)showloading {
    TJHud *hud = [TJHud showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.8];
    hud.mode = MBProgressHUDModeCustomView;
    hud.removeFromSuperViewOnHide = YES;
    CGPoint offset = hud.offset;
    offset.y = 0;
    hud.offset = offset;
    hud.margin = 20;
    SPActivityIndicatorView *loadingView = [[SPActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
    hud.customView = loadingView;
    [loadingView startAnimating];
    loadingView.tintColor = UIColor.whiteColor;

 }

+ (void)hiddenloading {
  [TJHud hideHUDForView:[UIApplication sharedApplication].delegate.window  animated:YES];
}


@end
